package com.paperyy.module.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.paperyy.module.bean.Consume;
import com.paperyy.module.bean.User;
import com.paperyy.module.dao.ConsumeDao;
import com.paperyy.module.service.ConsumeService;
import com.paperyy.module.service.impl.ConsumeServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import static net.sf.jsqlparser.util.validation.metadata.NamedObject.user;

@Controller
@RequestMapping("/consume")
public class ConsumeController {

    @Autowired
    private ConsumeServiceImpl consumeServiceImpl;
    @Autowired
    private ConsumeDao consumeDao;


    @RequestMapping("/selectPage")
    public String selectPage(Model model, @RequestParam(value = "current", defaultValue = "1") Integer current, @RequestParam(value = "size", defaultValue = "5") Integer size) {

        //当前页，页面大小
        Page<Consume> consumePage = new Page<>(current, size);
        consumeDao.selectPage(consumePage, null);
        //页数
        consumePage.getPages();
        //当前这一页的数据
        model.addAttribute("lists", consumePage);
        //下一页
        model.addAttribute("next",current+1);
        //上一页
        model.addAttribute("previous",current-1);
        //总页数
        model.addAttribute("final",consumePage.getPages());
        //当前页码
        model.addAttribute("current",current);

        return "consume";

    }

}
